//
//  ViewController.m
//  UI02_HomeWork_02
//
//  Created by Bodi on 16/6/6.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property(nonatomic, retain)UIImageView  *animationImageView;
@end

@implementation ViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self creatImageView];
    [self createAnimationImage];
    [self createAnimationImage1];
    [self createAnimationImage2];
    [self createAnimationImage3];
    [self createAnimationImage4];
    [self creatSlider];
    
}
- (void)creatImageView{
    UIImage *image = [UIImage imageNamed:@"BackGround.png"];
    UIImageView *backgroundImageView = [[UIImageView alloc]initWithImage:image];
    backgroundImageView.frame = [UIScreen mainScreen].bounds;
    [self.view addSubview:backgroundImageView];
    [backgroundImageView release];



}
- (void)createAnimationImage{
    self.animationImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"BZombie1.tiff"]];
    self.animationImageView.frame = CGRectMake(300, 100, 100, 100);
    [self.view addSubview:_animationImageView];
    [_animationImageView release];
    NSMutableArray *mutableArray = [NSMutableArray arrayWithCapacity:25];
    for (int i= 1; i <= 25; i++) {
        NSString *name = [NSString stringWithFormat:@"BZombie%d.tiff",i];
        UIImage *animationImage = [UIImage imageNamed:name];
        [mutableArray addObject:animationImage];
    }
    
    self.animationImageView.animationImages = mutableArray;
    
   self. animationImageView.animationDuration = 2.0;
    
    [_animationImageView startAnimating];
    
    
}

- (void)createAnimationImage1{
    UIImageView *animationImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"zombie1.tiff"]];
    animationImageView.frame = CGRectMake(300, 150, 100, 100);
    [self.view addSubview:animationImageView];
    [animationImageView release];
    NSMutableArray *mutableArray = [NSMutableArray arrayWithCapacity:21];
    for (int i= 1; i <= 21; i++) {
        NSString *name = [NSString stringWithFormat:@"zombie%d.tiff",i];
        UIImage *animationImage = [UIImage imageNamed:name];
        [mutableArray addObject:animationImage];
    }
    
    animationImageView.animationImages = mutableArray;
    
    animationImageView.animationDuration = 2.0;
    
    [animationImageView startAnimating];
    
    
}

- (void)createAnimationImage2{
    UIImageView *animationImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gua1.tiff"]];
    animationImageView.frame = CGRectMake(80, 150, 100, 100);
    [self.view addSubview:animationImageView];
    [animationImageView release];
    NSMutableArray *mutableArray = [NSMutableArray arrayWithCapacity:16];
    for (int i= 1; i <= 16; i++) {
        NSString *name = [NSString stringWithFormat:@"gua%d.tiff",i];
        UIImage *animationImage = [UIImage imageNamed:name];
        [mutableArray addObject:animationImage];
    }
    
    animationImageView.animationImages = mutableArray;
    
    animationImageView.animationDuration = 2.0;
    
    [animationImageView startAnimating];
    
    
}

- (void)createAnimationImage3{
    UIImageView *animationImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"flower1.tiff"]];
    animationImageView.frame = CGRectMake(80, 300, 80, 80);
    [self.view addSubview:animationImageView];
    [animationImageView release];
    NSMutableArray *mutableArray = [NSMutableArray arrayWithCapacity:18];
    for (int i= 1; i <= 18; i++) {
        NSString *name = [NSString stringWithFormat:@"flower%d.tiff",i];
        UIImage *animationImage = [UIImage imageNamed:name];
        [mutableArray addObject:animationImage];
    }
    
    animationImageView.animationImages = mutableArray;
    
    animationImageView.animationDuration = 2.0;
    
    [animationImageView startAnimating];
    
    
}

- (void)createAnimationImage4{
    UIImageView *animationImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"plants1.tiff"]];
    animationImageView.frame = CGRectMake(80, 400, 100, 100);
    [self.view addSubview:animationImageView];
    [animationImageView release];
    NSMutableArray *mutableArray = [NSMutableArray arrayWithCapacity:9];
    for (int i= 1; i <= 9; i++) {
        NSString *name = [NSString stringWithFormat:@"plants%d.tiff",i];
        UIImage *animationImage = [UIImage imageNamed:name];
        [mutableArray addObject:animationImage];
    }
    
    animationImageView.animationImages = mutableArray;
    
    animationImageView.animationDuration = 2.0;
    
    [animationImageView startAnimating];
    
    
}






-(void)creatSlider{

    UISlider *slide = [[UISlider alloc]initWithFrame:CGRectMake(100, 500, 200, 50)];
    [self.view addSubview:slide];
    slide.minimumValue = 0;
    slide.maximumValue = 1.0;
    [slide release];
    [slide addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];


}
-(void)sliderAction:(UISlider *)hs{

    self.animationImageView.animationDuration = hs.maximumValue - hs.value;
    [self.animationImageView startAnimating];

}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
